import _ from "lodash";

const textColor = ["text-primary", "text-success", "text-danger", "text-warning", "text-info", "text-secondary"];
const bgColor = ["bg-primary", "bg-success", "bg-danger", "bg-warning", "bg-info"];
const tagColor = ["primary", "success", "info", "warning", "danger"];

function calculateModNumber(value: string | number, max: number): number {
    // 如果 value 是 undefined 或 null，返回 0
    if (value == null) {
        return 0;
    }

    // 如果 value 是数字或可以转换为数字，直接计算模数
    if (!isNaN(Number(value))) {
        const numValue = Number(value);
        return numValue % max;
    }

    // 如果 value 是字符串，计算字符编码的累加模数
    let modNumbers = 0;
    value=value+""
    for (let i = 0; i < value.length; i++) {
        modNumbers = (modNumbers + value.charCodeAt(i)) % max; // 避免数值过大
    }
    return modNumbers;
}

export function getTypeColor(value: string): string {
    const modNumber = calculateModNumber(value, tagColor.length);
    return tagColor[modNumber];
}

export function getTextColor(value: string): string {
    const modNumber = calculateModNumber(value, textColor.length);
    return textColor[modNumber];
}
export function getBgColor(value: string): string {
    const modNumber = calculateModNumber(value, bgColor.length);
    return bgColor[modNumber];
}
